package com.riwon.im.websocket;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.corundumstudio.socketio.SocketIOServer;
import com.riwon.im.common.constant.UserConstant;
import com.riwon.im.pojo.User;
import com.riwon.im.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;

import javax.annotation.Resource;


/**
 * @author wpy
 */
//@Component
public class ServerRunner implements CommandLineRunner {

    @Resource
    private IUserService userServiceImpl;

    private final SocketIOServer server;
  
    @Autowired
    public ServerRunner(SocketIOServer server) {  
        this.server = server;  
    }  
  
    @Override  
    public void run(String... args) throws Exception {  
        server.start();
        User user = new User();
        user.setState(UserConstant.State.OFFLINE.getCode());
        userServiceImpl.update(user,new EntityWrapper<>());
    }  
}  